<template>
	<om-formsub-outer :index="index" :checkedit="checkedit" :deleteBtn="false">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import {errorModal,ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData()
		},
		methods:{
			onSelectEndTime(){
				let _that = this
				let endtime1 = new Date(_that.$refs.autoform.formdata.endTime1 + ":00")
				let endtime = new Date(_that.$refs.autoform.formdata.endTime + ":00")
				let title1 = _that.$refs.autoform.getEditorTitle("backLeave","endTime1")
				let title2 = _that.$refs.autoform.getEditorTitle("backLeave","endTime")
				if(endtime>endtime1){
					errorModal(_that,'提示信息',title1+"不能大于"+title2+"("+_that.$refs.autoform.formdata.endTime1+")，请重新选择！")
					_that.$refs.autoform.clear("backLeave","endTime")
					return
				}
				_that.om.request(
					'taskLeave/getLeaveDay',
					{
						startTime: _that.$refs.autoform.formdata.startTime,
						endTime:_that.$refs.autoform.formdata.endTime,
						infoId: _that.$refs.autoform.formdata.infoId
					}
				).then(res=>{
					if(res.succeed){
						_that.$refs.autoform.changeEditor("backLeave","leaveDay","type","labelbox")
						_that.$refs.autoform.changeEditor("backLeave","leaveHours","type","labelbox")
						_that.$refs.autoform.changeEditor("backLeave","leaveMin","type","labelbox")
						_that.$refs.autoform.formdata.leaveDay = res.value.day
						_that.$refs.autoform.formdata.leaveHours = res.value.hours
						_that.$refs.autoform.formdata.leaveMin = res.value.min
						_that.$refs.autoform.formdata.leaveTime = res.value.days
					}else{
						_that.$refs.autoform.changeEditor("backLeave","leaveDay","type","numberbox")
						_that.$refs.autoform.changeEditor("backLeave","leaveDay","prompt","请输入")
						_that.$refs.autoform.changeEditor("backLeave","leaveHours","type","numberbox")
						_that.$refs.autoform.changeEditor("backLeave","leaveHours","prompt","请输入")
						_that.$refs.autoform.changeEditor("backLeave","leaveMin","type","numberbox")
						_that.$refs.autoform.changeEditor("backLeave","leaveMin","prompt","请输入")
					}
				})
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("backLeave","endTime","noInitDate","true",_that.autoformdata)
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
